package com.dyzx.hbb.modules.finance.controller;

import com.dyzx.hbb.common.config.MyLambdaQueryWrapper;
import com.dyzx.hbb.common.controller.BaseValidController;
import com.dyzx.hbb.modules.finance.entity.FinanceEmsTemplate;
import com.dyzx.hbb.modules.finance.query.FinanceEmsTemplateQuery;
import com.dyzx.hbb.modules.finance.service.FinanceEmsTemplateService;
import com.dyzx.hbb.modules.finance.vo.FinanceEmsTemplateUVO;
import com.dyzx.hbb.modules.finance.vo.FinanceEmsTemplateVO;
import com.dyzx.hbb.security.context.SecurityContextHolder;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/finance/ems/template")
@RestController
public class FinanceEmsTemplateController extends BaseValidController<FinanceEmsTemplateService, FinanceEmsTemplate, FinanceEmsTemplateQuery, FinanceEmsTemplateVO, FinanceEmsTemplateUVO> {

    @Autowired
    private FinanceEmsTemplateService service;

    @Override
    protected FinanceEmsTemplate addValid(FinanceEmsTemplateVO entity) {
        Long userId = SecurityContextHolder.getUserId();
        FinanceEmsTemplate data = new FinanceEmsTemplate();
        BeanUtils.copyProperties(entity, data);
        data.setOperatorId(userId);
        data.setDeliveryStaffId(userId);
        data.setDeliveryTime(System.currentTimeMillis());
        return data;
    }

    @Override
    protected FinanceEmsTemplate editValid(FinanceEmsTemplateUVO entity) {
        return null;
    }

    @Override
    protected FinanceEmsTemplateService getBaseService() {
        return service;
    }

    @Override
    protected MyLambdaQueryWrapper<FinanceEmsTemplate> queryWrapper(FinanceEmsTemplateQuery query) {
        MyLambdaQueryWrapper<FinanceEmsTemplate> queryWrapper = new MyLambdaQueryWrapper<>();
        queryWrapper.select(FinanceEmsTemplate::getId, FinanceEmsTemplate::getEmsNo, FinanceEmsTemplate::getContactName, FinanceEmsTemplate::getPhone, FinanceEmsTemplate::getEmail, FinanceEmsTemplate::getStatus,
                FinanceEmsTemplate::getCreateDate, FinanceEmsTemplate::getUpdateDate
                , FinanceEmsTemplate::getDeliveryTime, FinanceEmsTemplate::getReceivedTime, FinanceEmsTemplate::getInspectionTime, FinanceEmsTemplate::getReturnApplyTime, FinanceEmsTemplate::getReturnProcessTime,
                FinanceEmsTemplate::getFinishTime, FinanceEmsTemplate::getRefundAmount, FinanceEmsTemplate::getAmount, FinanceEmsTemplate::getQuantity,
                FinanceEmsTemplate::getReturnQuantity,FinanceEmsTemplate::getName, FinanceEmsTemplate::getDescription, FinanceEmsTemplate::getUnit, FinanceEmsTemplate::getEmsNo);
/*
        FinanceEmsTemplate::getDeliveryStaff,
                FinanceEmsTemplate::getReceivedStaff,
                FinanceEmsTemplate::getReturnApplyStaff,
                FinanceEmsTemplate::getFinishStaff*/
        queryWrapper.userName(FinanceEmsTemplate::getDeliveryStaffId).as("delivery_staff_name");
        queryWrapper.userName(FinanceEmsTemplate::getReceivedStaffId).as("received_staff_name");
        queryWrapper.userName(FinanceEmsTemplate::getReturnApplyStaffId).as("return_apply_staff_name");
        queryWrapper.userName(FinanceEmsTemplate::getFinishStaffId).as("finish_staff_name");


        return queryWrapper;
    }

    @Override
    protected MyLambdaQueryWrapper<FinanceEmsTemplate> queryInfoWrapper() {
        MyLambdaQueryWrapper<FinanceEmsTemplate> queryWrapper = new MyLambdaQueryWrapper<>();
        queryWrapper.select(FinanceEmsTemplate::getId, FinanceEmsTemplate::getEmsNo, FinanceEmsTemplate::getContactName, FinanceEmsTemplate::getPhone, FinanceEmsTemplate::getEmail, FinanceEmsTemplate::getStatus,
                FinanceEmsTemplate::getCreateDate, FinanceEmsTemplate::getUpdateDate
                , FinanceEmsTemplate::getDeliveryTime, FinanceEmsTemplate::getReceivedTime, FinanceEmsTemplate::getInspectionTime, FinanceEmsTemplate::getReturnApplyTime, FinanceEmsTemplate::getReturnProcessTime,
                FinanceEmsTemplate::getFinishTime, FinanceEmsTemplate::getRefundAmount, FinanceEmsTemplate::getAmount, FinanceEmsTemplate::getQuantity,
                FinanceEmsTemplate::getReturnQuantity,FinanceEmsTemplate::getName, FinanceEmsTemplate::getDescription, FinanceEmsTemplate::getUnit, FinanceEmsTemplate::getEmsNo);
/*
        FinanceEmsTemplate::getDeliveryStaff,
                FinanceEmsTemplate::getReceivedStaff,
                FinanceEmsTemplate::getReturnApplyStaff,
                FinanceEmsTemplate::getFinishStaff*/
        queryWrapper.userName(FinanceEmsTemplate::getDeliveryStaffId).as("delivery_staff_name");
        queryWrapper.userName(FinanceEmsTemplate::getReceivedStaffId).as("received_staff_name");
        queryWrapper.userName(FinanceEmsTemplate::getReturnApplyStaffId).as("return_apply_staff_name");
        queryWrapper.userName(FinanceEmsTemplate::getFinishStaffId).as("finish_staff_name");


        return queryWrapper;
    }
}
